#include <string>
using namespace std;
/*QIF ASSEMBLY CODE */
#define LOD 1 // LOD l,a	LOAD VALUE a TO A VARAIBLE l
#define LD2 2 // LD2 i		LOAD LITERAL
#define ADD 3 // ADD		ADDITION
#define SUB 4//  SUB		SUBSTRACTION
#define MUL 5//  MUL		MUTIPLICATION

#define MAX_CODE_MEMORY 1024

char code[MAX_CODE_MEMORY]; // store the opcode and value
string var[MAX_CODE_MEMORY]; // store the variable name
string stack[MAX_CODE_MEMORY]; // the stack in the compiler
int pc = 0;
int top;

void writeCode(int op){
	if(pc<MAX_CODE_MEMORY){
		code[pc++] = (char)op;
	}
}
void writeCode2(int op, int value){
	writeCode(op);
	code[pc] = char(value >> 8); 	code[pc+1] = char(value);	
	pc = pc+2;
}
void writeCode3(int op, string varname, int value){
	var[pc] = varname;
	writeCode2(op,value);	
}
//get the op code
int getNextIntruction(){
	return (int)code[pc++];
}
//get the number
int getNextInstruction2(){
	int p1, p2;
	p1 = (int) code[pc];
	p2 =  (int) code[pc=1];
	pc = pc+2;
	return (p1<<8 + p2);

}



// push variable or value to the stack
void push(string name){
	if(top<MAX_CODE_MEMORY){
		stack[top++] = name;
	}
	
}
// pop variable or value from the stack
string pop(){
	if(top >0)
	return stack[top--];
}
void init(){
	pc=1;
}







